package io.handlerstream;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import org.junit.Test;

public class BufferStreamDemo {
	
	@Test
	public void input() throws IOException {
		
		FileInputStream fis2 = new FileInputStream("哈利波特.txt");
		BufferedInputStream bis2 = new BufferedInputStream(fis2);
		byte[] arr2 = new byte[fis2.available()];
		// 用处理流读取
		bis2.read(arr2);
		
		bis2.close();
		fis2.close();
		
		// new String(byte[], 指定字符编码)
		System.out.println(new String(arr2,"gbk"));
	}
	
	@Test
	public void output() throws IOException {
		FileOutputStream fos = new FileOutputStream("c.txt");
		BufferedOutputStream bos = new BufferedOutputStream(fos);
		
		bos.write("哈哈哈".getBytes());
		bos.flush();
		
		bos.close();
		fos.close();
	}
}
